package script.learn
{
	import eventUtil.EventCenter;
	
	import laya.events.Event;
	import laya.ui.View;
	import laya.utils.Handler;
	
	import model.HttpErrorCode;
	import model.HttpRequestUtil;
	import model.lesson.BookContentSetting;
	import model.lesson.LearnEnglishModel;
	import model.lesson.LessonVo;
	
	import script.ViewManager;
	import script.baseView.BaseViewController;
	import script.learn.item.LessonCell;
	import script.prefabScript.BookContents;
	
	import ui.learn.ChineseBookContentPanelUI;
	import ui.learn.EnglishBookContentPanelUI;
	
	public class ChooseChineseLessonController extends BaseViewController
	{
		private var uiSkin:ChineseBookContentPanelUI;
		
		private var param:Object;
		
		public function ChooseChineseLessonController()
		{
			super();
		}
		
		override public function onStart():void
		{
			uiSkin = this.owner as ChineseBookContentPanelUI;
			
			var classlevel:int = param.orderNum;
			
			var contents:View = new BookContentSetting.CHINESE_CONTENT_PANEL[classlevel - 1];
			
			uiSkin.bookContensPanel.addChild(contents);
			
			uiSkin.reciteWords.on(Event.CLICK,this,function(){
				
				ViewManager.instance.openView(ViewManager.VIEW_CHOOSE_RECITE_DATE_PANEL,false,param);
			});
			
			EventCenter.instance.on(EventCenter.OPEN_BOOK_PAGE,this,openBookPage);

			//var postdata:String = "classlevelId=" + param.id;
			//HttpRequestUtil.instance.Request(HttpRequestUtil.httpUrl + HttpRequestUtil.getLessons,this,onGetLessonInfo,postdata,"post");
			
		}
		private function onGetLessonInfo(data:*):void
		{
			if(this.destroyed)
				return;
			
			var result:Object = JSON.parse(data);
			if(result.code == HttpErrorCode.OK)
			{
				//uiSkin.lessonlist.array = result.lessonlist;
			}
		}
		
		public function updatelessonlist(cell:LessonCell):void
		{
			cell.setData(cell.dataSource);
		}
		
		public function selectLesson(index:int):void
		{
			if(index < 0)
				return;
			
			//LearnEnglishModel.instance.lessondata = new LessonVo(uiSkin.lessonlist.array[index]);
			
			ViewManager.instance.openView(ViewManager.VIEW_LEARN_WORD_PANEL,false);
			
			//uiSkin.lessonlist.selectedIndex = -1;
		}
		
		private function openBookPage(page:int):void
		{
			ViewManager.instance.openView(ViewManager.VIEW_BOOK_PAGE_PANEL,false,{"subject":param.levelType,"level":param.orderNum,"page":page});

		}
		
		public override function onDestroy():void
		{
			EventCenter.instance.off(EventCenter.OPEN_BOOK_PAGE,this,openBookPage);
		}
	}
}